use serde::Deserialize;

#[derive(Debug, Clone, Deserialize)]
pub struct Satoken {
    name: Option<String>,
    prefix: Option<String>,
    timeout: Option<u64>,
    #[serde(rename = "active-timeout")]
    active_timeout: Option<i64>,
    #[serde(rename = "is-concurrent")]
    is_concurrent: Option<bool>,
    #[serde(rename = "token-style")]
    token_style: Option<SatokenType>,
    #[serde(rename = "secret-key")]
    secret_key: Option<String>,
}

impl Satoken {
    pub fn name(&self) -> &str { &self.name.as_deref().unwrap_or("Satoken") }
    pub fn prefix(&self) -> &str {
        &self.prefix.as_deref().unwrap_or("Bearer")
    }

    pub fn timeout(&self) -> u64 {
        self.timeout.unwrap_or(604800)
    }

    pub fn active_timeout(&self) -> i64 {
        self.active_timeout.unwrap_or(3600)
    }

    pub fn is_concurrent(&self) -> bool {
        self.is_concurrent.unwrap_or(true)
    }

    pub fn token_style(&self) -> SatokenType {
        self.token_style.clone().unwrap_or(SatokenType::Tik)
    }

    pub fn secret_key(&self) -> &str { &self.secret_key.as_deref().unwrap_or("sa-token") }
}

#[derive(Debug, Clone, Deserialize)]
pub enum SatokenType {
    Uuid,
    SimpleUuid,
    Random32,
    Random64,
    Random128,
    Tik
}